package com.example.qingyiapp.ui.activity.fragment.fragment_AddressUI.address_adapter3;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.example.qingyiapp.R;
import com.example.qingyiapp.ui.activity.fragment.fragment_AddressUI.address_bean.JavaBean_lv3;

import java.util.List;

public class adapter_address_lv3_rv3 extends RecyclerView.Adapter<adapter_address_lv3_rv3.MyViewHolder> {

    List<JavaBean_lv3.DataBean.ListBean> list;
    Context context;

    public adapter_address_lv3_rv3(List<JavaBean_lv3.DataBean.ListBean> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new MyViewHolder(LayoutInflater.from(context).inflate(R.layout.address_rows3_rv,viewGroup,false));
    }


    @Override
    public void onBindViewHolder(@NonNull MyViewHolder myViewHolder, final int i) {

        Glide.with(context).load(list.get(i).getUsercover()).apply(RequestOptions.circleCropTransform()).into(myViewHolder.head);
        Glide.with(context).load(list.get(i).getPostcover()).into(myViewHolder.imageView);

//        postcover  praise_cnt  enshrine_cnt
        myViewHolder.title.setText(list.get(i).getTitle());
        myViewHolder.num1.setText(list.get(i).getEnshrine_cnt());
        myViewHolder.num2.setText(list.get(i).getPraise_cnt());

        myViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                myLintener.clickIntent(i);
            }
        });
    }


    @Override
    public int getItemCount() {
        return list.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder{

        ImageView imageView;
        ImageView head;
        TextView title,num1,num2;

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);

            imageView = itemView.findViewById(R.id.rows3_img1);
            head = itemView.findViewById(R.id.rows3_head);
            title = itemView.findViewById(R.id.rows3_title);
            num1 = itemView.findViewById(R.id.rows3_num1);
            num2 = itemView.findViewById(R.id.rows3_num2);

        }
    }

    interface MyLintener{
        void clickIntent(int pisition);
    }

    MyLintener myLintener;

    public void setMyLintener(MyLintener myLintener) {
        this.myLintener = myLintener;
    }
}
